<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("admin.articleCategory.add")} - 766 SMART HOME</title>
<meta name="author" content="BIZ Team" />
<meta name="copyright" content="BIZ" />
<link href="${base}/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
<link href="${base}/resources/public/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${base}/resources/admin/js/jquery.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/common.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/input.js"></script>
<script type="text/javascript" src="${base}/resources/public/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript">
$().ready(function() {

	var $inputForm = $("#inputForm");
	
	[@flash_message /]

	// 表单验证
	$inputForm.validate({
		rules: {
			name: "required",
			order: "digits"
		}
	});
	var setting = {
			view: {
				showIcon: showIconForTree
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onClick: zTreeOnClick
			}
		};

		var zNodes =${nodes};

		function zTreeOnClick(event, treeId, treeNode) {
			var idStr=treeNode.id;
			if(idStr==0){
				idStr="";
			}
			$("#dictionary_parent_id").val(idStr);
		    //alert(treeNode.tId + ", " + treeNode.name);
		};
		function showIconForTree(treeId, treeNode) {
			return !treeNode.isParent;
		};
		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		});
});
function delDictionary(obj){
	var id=$(obj).attr("dId");
	var basePath=$("#basePath").val();
	$.post(basePath+"/admin/dictionary/del.jhtml",{id:id},function(data){
		if(data.type=="success"){
			$(obj).parent().parent().remove();
			$.message(data.type,data.content);
		}
	},"json");
}
</script>
</head>
<body>
	<div class="path">
		<a href="${base}/admin/common/index.jhtml">${message("admin.path.index")}</a> &raquo; ${message("admin.dictionary.edit")}
	</div>
	<form id="inputForm" action="update.jhtml" method="post">
		<input type="hidden" id="basePath" value="${base}"/>
		<table class="input">
			<tr>
				<th>
					<span class="requiredField">*</span>${message("Dictionary.title")}:
				</th>
				<td>
					<input type="text" id="title" name="title" class="text" maxlength="200" value="${dictionary.title}"/>
					<input type="hidden" name="id" value="${dictionary.id}"/>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">&nbsp;</span>${message("Dictionary.description")}:
				</th>
				<td>
					<input type="text" id="description" name="description" class="text" maxlength="200" value="${dictionary.description}" />
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>上级节点:
				</th>
				<td>
					<div class="zTreeDemoBackground">
						<ul id="treeDemo" class="ztree"></ul>
					</div>
					<input id="dictionary_parent_id" type="hidden" name="parentId"/>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>${message("Dictionary.flag")}:
				</th>
				<td>
					<select id="flag" name="flag">
						<option value="true"  [#if dictionary.flag] selected="selected"[/#if] >${message("Dictionary.flagTrue")}</option>
						<option value="false" [#if dictionary.flag][#else]selected="selected"[/#if] >${message("Dictionary.flagFalse")}</option>
					</select>
				</td>
			</tr>
			<tr>
				<th><span>排序</span></th>
				<td>
					<input type="text" class="text" name="order" value="${dictionary.order}"/>
				</td>
			</tr>
		</table>
		[#if dictionary.childrens??]
			<table class="list">
				<tr>
					<th colspan="5">
						下级列表
					</th>
				</tr>
				<tr>
					<th>
						名称
					</th>
					<th>
						描述
					</th>
					<th>
						上级名称
					</th>
					<th>
						是否有效
					</th>
					<th>
						操作
					</th>
				</tr>
				[#list dictionary.childrens as item]
					<tr>
						<td>
							${item.title}
						</td>
						<td>
							${item.description}
						</td>
						<td>
							${dictionary.title}
						</td>
						<td>
							[#if item.flag]${message("Dictionary.flagTrue")}[#else]${message("Dictionary.flagFalse")}[/#if]
						</td>
						<td>
							<a href="edit.jhtml?id=${item.id}">[${message("admin.common.edit")}]</a>
							<a href="show.jhtml?id=${item.id}">[${message("admin.common.view")}]</a>
							<a href="javascript:;" dId="${item.id}" onClick="delDictionary(this)">[删除]</a>
						</td>
					</tr>
				[/#list]
			</table>
		[/#if]
		<table class="input">
			<tr>
				<th>
					&nbsp;
				</th>
				<td>
					<input type="submit" class="button" value="${message("admin.common.submit")}" />
					[#if dictionary.parent??] 
						<input type="button" class="button" value="查看上级" onclick="location.href='show.jhtml?id=${dictionary.parent.id}'" />
					[/#if]
					<input type="button" class="button" value="${message("admin.common.back")}" onclick="location.href='list.jhtml'" />
				</td>
			</tr>
		</table>
	</form>
</body>
</html>